package cz.muni.fi.pb138.videoweb2013.servlets;

import cz.muni.fi.pb138.videoweb2013.backend.MediumManager;
import cz.muni.fi.pb138.videoweb2013.backend.MediumManagerImpl;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;

/**
 * delete action
 * 
 * @author Filip
 */
@UrlBinding("/action/Delete.jsp")
public class DeleteActionBean implements ActionBean{
    private ActionBeanContext context;
    private static int id;

    public ActionBeanContext getContext() {
        return context;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }
    
    public int getId(){
        return id;
    }
    
    public void setId(int id){
        this.id = id;
    }
    
    /**
     * deletes medium with id given by user from database
     * 
     * @return forward resolution to page Delete
     */
    @DefaultHandler
    public Resolution search() {
        MediumManager mm = new MediumManagerImpl();
        mm.deleteRecord(mm.getMediumById(id));

        return new ForwardResolution("/Delete.jsp");
    }
    
}
